package com.holyant.goods.dto;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.core.annotation.Excel;
import com.holyant.goods.enums.SpecsQtyEnum;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.ToString;

import java.math.BigDecimal;
import java.util.Objects;

/**
 * @Author: Ssw
 * @CreateTime: 2022-11-22  11:18
 * @Description:
 */

@Data
@ToString
public class PriceImportBase {

    @Excel(name = "*sku编码",sort = 1000)
    protected String skuCode;

    @Excel(name = "商品名称",sort = 1001)
    protected String goodsName;

    @Excel(name = "商品条码",sort = 1002)
    protected String goodsBarcode;


    // @NonNullVerification(message = "效期格式不正确!", regexp = YEAR_MONTH_DATE)
    @Excel(name = "效期" ,sort = 1003, prompt = "例:2022-09-01", cellType = Excel.ColumnType.STRING)
    protected String expireDate;

    //@Excel(name = "报价方式",prompt = "包邮不包税、包邮包税、不包邮不包税")
    protected String quoteMethod;
    protected Integer quoteMethodVal;

    @Excel(name = "*币种",prompt = "人民币、港币、美金、澳元、欧元,日元",sort = 1004)
    protected String curType;
    protected Integer curTypeVal;


    protected String pcs1;


    protected String pcs2;


    protected String pcs3;

    protected String pcs4;


    protected String pcs5;


    protected String pcs6;

    @Excel(name = "*pcs",combo={"1","2","3","4","5","6"},sort = 1005,prompt = "请输入1、2、3、4、5、6")
    protected Integer pcs;


    @Excel(name = "价格（包邮不包税）",scale = 4,sort = 1006)
    protected BigDecimal freeMailNotTax;


    @Excel(name = "价格（包邮包税）",scale = 4,sort = 1007)
    protected  BigDecimal freeMailFreeTax;


    @Excel(name = "价格（不包邮不包税）",scale = 4,sort = 1008)
    protected  BigDecimal notMailNotTax;


    /** 价格json */
    @ApiModelProperty(hidden = true,name = "价格json")
    protected String priceObj;



    public String getPriceObj() {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put(SpecsQtyEnum.ONE.name(), getPcs1());
        jsonObject.put(SpecsQtyEnum.TWO.name(), getPcs2());
        jsonObject.put(SpecsQtyEnum.THREE.name(), getPcs3());
        jsonObject.put(SpecsQtyEnum.FOUR.name(), getPcs4());
        jsonObject.put(SpecsQtyEnum.FIVE.name(), getPcs5());
        jsonObject.put(SpecsQtyEnum.SIX.name(), getPcs6());
        return jsonObject.toString();
    }

    public void initPrice() {
        if (Objects.nonNull(priceObj)) {
            JSONObject jsonObject = JSON.parseObject(priceObj);
            for (int i = 1; i <= 6; i++) {
                SpecsQtyEnum specsQtyEnum = SpecsQtyEnum.parseByName(String.valueOf(i));
                if (i == 1 && null != jsonObject.getBigDecimal(specsQtyEnum.name())){
                    this.setPcs1(jsonObject.getBigDecimal(specsQtyEnum.name()).toString());
                    continue;
                }
                if (i == 2 && null != jsonObject.getBigDecimal(specsQtyEnum.name())){
                    this.setPcs2(jsonObject.getBigDecimal(specsQtyEnum.name()).toString());
                    continue;
                }
                if (i == 3 && null != jsonObject.getBigDecimal(specsQtyEnum.name())){
                    this.setPcs3(jsonObject.getBigDecimal(specsQtyEnum.name()).toString());
                    continue;
                }
                if (i == 4 && null != jsonObject.getBigDecimal(specsQtyEnum.name())){
                    this.setPcs4(jsonObject.getBigDecimal(specsQtyEnum.name()).toString());
                    continue;
                }
                if (i == 5 && null != jsonObject.getBigDecimal(specsQtyEnum.name())){
                    this.setPcs5(jsonObject.getBigDecimal(specsQtyEnum.name()).toString());
                    continue;
                }
                if (i == 6 && null != jsonObject.getBigDecimal(specsQtyEnum.name())){
                    this.setPcs6(jsonObject.getBigDecimal(specsQtyEnum.name()).toString());
                    continue;
                }
            }
        }
    }
}
